/******************************************************************************
* File description: maintenanceothers.qml
* Function: 维护：其他维护
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-30
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.14

Item {
    id: root

    /* property 定义开始 */

    // 私有
    // TabBar标题
    property var _barTitleList: ["IP地址修改", "外部件维护"]
    // 是否为网络通信
    property bool isWeb: true

    // 信号
    signal currentIndexChanged(int index);

    /* property 定义结束 */

    // tabbar
    TabBar {
        id: tabBar
        width: implicitWidth
        height: 20
        anchors {
            top: parent.top
            left: parent.left
            topMargin: 20
            leftMargin: 25
        }
        background: Rectangle{color: "transparent"}
        spacing: 24

        Repeater {
            model: root._barTitleList

            TabButton {
                implicitHeight: parent.height

                // 文字
                contentItem: Label{
                    id: text
                    anchors {
                        fill: parent
                    }
                    bottomPadding: 2
                    font {
                        pixelSize: 16
                    }
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                    color: "#FF222222"
                    text: qsTr(modelData)
                }

                // 背景
                background: Rectangle{
                    color: "transparent"

                    // 绘制下边框
                    Canvas {
                        anchors.fill: parent
                        visible: index === tabBar.currentIndex
                        antialiasing: true
                        onPaint: {
                            var ctx = getContext("2d")
                            ctx.strokeStyle = "#FF2F42CD"
                            ctx.lineWidth = 6
                            ctx.beginPath()
                            ctx.moveTo(0, height)
                            ctx.lineTo(width, height)
                            ctx.stroke()
                        }
                    }
                }

                onClicked: {
                    tabBar.currentIndexChanged(index)
                    mainContentLayout.currentIndex = tabBar.currentIndex
                }
            }
        }
    }

    // 主内容
    StackLayout {
        id: mainContentLayout
        anchors {
            fill: parent
            topMargin: tabBar.height + 36
        }

        // IP地址修改
        Item {
            id: ipAddrChanged
            Layout.fillWidth: true
            Layout.fillHeight: true

            ColumnLayout {
                id: ipAddrChangedLayout
                anchors.fill: parent

                // 单选按钮部分
                Item {
                    id: ipAddrChangedRadioBtnsCon
                    Layout.fillWidth: true
                    Layout.preferredHeight: 15

                    RowLayout {
                        anchors {
                            fill: parent
                            leftMargin: 49
                        }

                        // 通信类型
                        Label {
                            Layout.alignment: Qt.AlignVCenter
                            font.pixelSize: 16
                            color: "#FF222222"
                            text: "通信类型"
                        }

                        CustomHorSpacerItem {}

                        ButtonGroup {
                            id: communicationExclusiveGroup
                        }

                        // 网络通信
                        CustomRadioButton {
                            id: webCommunication
                            checked: true
                            text: "网络通信"
                            ButtonGroup.group: communicationExclusiveGroup
                            onCheckedChanged: {
                                if(webCommunication.checked) root.isWeb = true
                            }
                        }

                        // USB通信
                        CustomRadioButton {
                            id: usbCommunication
                            checked: false
                            text: "USB通信"
                            ButtonGroup.group: communicationExclusiveGroup
                            onCheckedChanged: {
                                if(usbCommunication.checked) root.isWeb = false
                            }
                        }

                        CustomHorSpacerItem {}
                    }
                }

                // 文本框部分
                Item {
                    id: ipAddrChangedInputsCon
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.leftMargin: 62
                    Layout.rightMargin: 62
                    Layout.topMargin: 16

                    ColumnLayout {
                        anchors.fill: parent

                        // IP地址
                        LabelTextInput {
                            id: ipAddrInput
                            visible: root.isWeb
                            Layout.fillWidth: true
                            Layout.preferredHeight: 40
                            inputWidth: width
                            inputHeight: height
                            placeholderText: ""
                            labelText: "IP地址"
                        }

                        // 端口号
                        LabelTextInput {
                            id: portInput
                            visible: root.isWeb
                            Layout.fillWidth: true
                            Layout.preferredHeight: 40
                            inputWidth: width
                            inputHeight: height
                            placeholderText: ""
                            labelText: "端口号"
                        }

                        // 串口号
                        LabelTextInput {
                            id: chuankouInput
                            visible: !root.isWeb
                            Layout.fillWidth: true
                            Layout.preferredHeight: 40
                            inputWidth: width
                            inputHeight: height
                            placeholderText: ""
                            labelText: "串口号"
                        }

                        // 波特率
                        LabelComboBox {
                            id: boTeLvComboBox
                            visible: !root.isWeb
                            Layout.fillWidth: true
                            Layout.preferredHeight: 40
                            comboBoxWidth: width
                            comboBoxHeight: height
                            showListMaxCountinPage: 5
                            model: ["4800"]
                            comboBoxText: "波特率"
                        }
                    }
                }

                // 底部按钮部分
                Item {
                    id: bottomBtnsCon
                    Layout.fillWidth: true
                    Layout.preferredHeight: 40
                    Layout.bottomMargin: 40
                    Layout.topMargin: 40

                    RowLayout {
                        anchors.fill: parent

                        CustomHorSpacerItem {}

                        // 取消
                        PureButton {
                            id: cancel
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureText: "取消"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        // 确认
                        PureButton {
                            id: submit
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureBtnColor: "#FF2F42CD"
                            pureHoveredColor: "#FF2F42CD"
                            pureLabelColor: "#FFFFFFFF"
                            pureFontHoveredColor: "#FFFFFFFF"
                            pureBtnBorderColor: "transparent"
                            pureText: "确定"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        CustomHorSpacerItem {}
                    }
                }
            }
        }

        // 外部件维护
        Item {
            id: outerPartMaintenance
            Layout.fillWidth: true
            Layout.fillHeight: true

            ColumnLayout {
                anchors.fill: parent

                Item {
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    Layout.leftMargin: 96
                    Layout.rightMargin: 96
                    Layout.topMargin: 36

                    // 功能按钮部分
                    GridLayout {
                        anchors.fill: parent
                        columns: 2
                        rows: 2
                        rowSpacing: 16
                        columnSpacing: 8

                        // 水泵开
                        PureButton {
                            id: shuiBengOn
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureBtnColor: "#FF2F42CD"
                            pureHoveredColor: "#FF2F42CD"
                            pureLabelColor: "#FFFFFFFF"
                            pureFontHoveredColor: "#FFFFFFFF"
                            pureBtnBorderColor: "transparent"
                            pureText: "水泵开"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        // 水泵关
                        PureButton {
                            id: shuiBengOff
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            isEnable: false
                            pureBtnColor: "#FF2F42CD"
                            pureHoveredColor: "#FF2F42CD"
                            pureLabelColor: "#FFFFFFFF"
                            pureFontHoveredColor: "#FFFFFFFF"
                            pureBtnBorderColor: "transparent"
                            pureText: "水泵关"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        // 风扇开
                        PureButton {
                            id: fengShanOn
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureBtnColor: "#FF2F42CD"
                            pureHoveredColor: "#FF2F42CD"
                            pureLabelColor: "#FFFFFFFF"
                            pureFontHoveredColor: "#FFFFFFFF"
                            pureBtnBorderColor: "transparent"
                            pureText: "风扇开"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        // 风扇关
                        PureButton {
                            id: fengShanOff
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            isEnable: false
                            pureBtnColor: "#FF2F42CD"
                            pureHoveredColor: "#FF2F42CD"
                            pureLabelColor: "#FFFFFFFF"
                            pureFontHoveredColor: "#FFFFFFFF"
                            pureBtnBorderColor: "transparent"
                            pureText: "风扇关"
                            // 关闭过渡效果
                            isTransition: false
                        }
                    }
                }

                Item {
                    Layout.fillWidth: true
                    Layout.preferredHeight: 40
                    Layout.topMargin: 40
                    Layout.bottomMargin: 77

                    // 下部按钮
                    RowLayout {
                        id: outerPartMaintenanceBottomBtns
                        anchors.fill: parent

                        CustomHorSpacerItem {}

                        // 取消
                        PureButton {
                            id: outerPartMaintenanceCancel
                            Layout.preferredWidth: 120
                            Layout.preferredHeight: 40
                            pureText: "取消"
                            // 关闭过渡效果
                            isTransition: false
                        }

                        CustomHorSpacerItem {}
                    }
                }
            }
        }

    }
}
